package com.shushan.discount.bean;

import com.android.net.bean.NetBaseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: AllCouponsBean
 * @Desciption: //所有优惠券的总数据bean
 * @author: zhangshihao
 * @date: 2018-08-30
 */
public class AllCouponsBean extends NetBaseBean {

    private List<CouponBean> noUseCouponBeans = new ArrayList<>();//未使用
    private List<CouponBean> isUseCouponBeans = new ArrayList<>();//已使用
    private List<CouponBean> overdueCouponBeans = new ArrayList<>();//已过期

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject == null){
            return;
        }
        JSONArray noUseArr = jsonObject.optJSONArray("no_use");
        if(noUseArr != null && noUseArr.length() > 0){
            for(int i=0;i<noUseArr.length();i++) {
                JSONObject noUseObj = noUseArr.optJSONObject(i);
                CouponBean bean = new CouponBean();
                bean.initByJson(noUseObj);
                noUseCouponBeans.add(bean);
            }
        }

        JSONArray isUseArr = jsonObject.optJSONArray("is_use");
        if(isUseArr != null && isUseArr.length() > 0){
            for(int i=0;i<isUseArr.length();i++){
                JSONObject isUseObj = isUseArr.optJSONObject(i);
                CouponBean bean = new CouponBean();
                bean.initByJson(isUseObj);
                isUseCouponBeans.add(bean);
            }
        }

        JSONArray overdueArr = jsonObject.optJSONArray("overdue");
        if(overdueArr != null && overdueArr.length() > 0){
            for(int i=0;i<overdueArr.length();i++){
                JSONObject obj = overdueArr.optJSONObject(i);
                CouponBean bean = new CouponBean();
                bean.initByJson(obj);
                overdueCouponBeans.add(bean);
            }
        }

    }

    public List<CouponBean> getNoUseCouponBeans() {
        return noUseCouponBeans;
    }

    public List<CouponBean> getIsUseCouponBeans() {
        return isUseCouponBeans;
    }

    public List<CouponBean> getOverdueCouponBeans() {
        return overdueCouponBeans;
    }

    public List<CouponBean> getCouponListByIndex(int index){
        List<CouponBean> couponBeans = new ArrayList<>();
        switch (index){
            case 0:
                couponBeans = noUseCouponBeans;
                break;
            case 1:
                couponBeans = isUseCouponBeans;
                break;
            case 2:
                couponBeans = overdueCouponBeans;
                break;
        }
        return couponBeans;
    }

}
